package BehaviorDesignPattern.MediatorPattern;


// 具体中介者类，负责管理各组件之间的交互
class ConcreteMediator implements Mediator {
    private Component1 component1;
    private Component2 component2;

    public void setComponent1(Component1 component1) {
        this.component1 = component1;
    }

    public void setComponent2(Component2 component2) {
        this.component2 = component2;
    }

    @Override
    public void notify(Component sender, String event) {
        if ("A".equals(event)) {
            System.out.print("中介者对A作出反应，并触发以下操作:");
            component2.doC();
        } else if ("B".equals(event)) {
            System.out.print("中介者对B作出反应，并触发以下操作:");
            component1.doC();
        }
    }
}